import { baseRequestClient, requestClient } from '#/api/request';

export namespace WareHouse {
  export interface Params {
    attr1: null;
  }

  export interface ChildChild {
    searchValue: null;
    createBy: null;
    createTime: null;
    updateBy: null;
    updateTime: null;
    remark: null;
    params: Params;
    areaId: null;
    areaCode: null;
    areaName: null;
    locationId: null;
    area: number;
    maxLoa: null;
    positionX: null;
    positionY: null;
    positionZ: null;
    enableFlag: null;
    frozenFlag: null;
    productMixing: null;
    batchMixing: null;
    attr1: null;
    attr2: null;
    attr3: null;
    attr4: null;
  }
  export interface RowChild {
    searchValue: null;
    createBy: null;
    createTime: null;
    updateBy: null;
    updateTime: null;
    remark: null;
    params: Params;
    locationId: null;
    locationCode: null;
    locationName: null;
    warehouseId: number;
    area: number;
    areaFlag: null;
    frozenFlag: null;
    attr1: null;
    attr2: null;
    attr3: null;
    attr4: null;
    children: ChildChild[];
  }

  export interface Row {
    id: number;
    searchValue: null;
    createBy: string;
    createTime: Date;
    updateBy: string;
    updateTime: Date;
    remark: string;
    params: Params;
    warehouseId: number;
    warehouseCode: string;
    warehouseName: string;
    location: null | string;
    area: number;
    userId: null | number;
    userName: null | string;
    charge: null | string;
    frozenFlag: string;
    attr1: boolean | null | string;
    attr2: null;
    attr3: number;
    attr4: number;
    children: RowChild[];
    action: string;
  }

  export interface GetListParams {
    pageNum: number;
    pageSize: number;
  }
  export interface GetListReturn {
    total: number;
    rows: Row[];
    code: number;
    msg: string;
  }
}

// 获取列表
export const getWareHouseTableList = (params: WareHouse.GetListParams) =>
  requestClient.get<WareHouse.GetListReturn>('/mes/wm/warehouse/list', {
    params,
  });

// 修改仓库设置
export const updateWareHouse = (data: WareHouse.Row) =>
  requestClient.put<WareHouse.GetListReturn>('/mes/wm/warehouse', data);
export const updateWareHouseStatus = (data: {
  frozenFlag: string;
  warehouseId: string;
}) => requestClient.put<WareHouse.GetListReturn>('/mes/wm/warehouse', data);

// 增加仓库设置
export const addWareHouse = (data: WareHouse.Row) =>
  requestClient.post<WareHouse.GetListReturn>('/mes/wm/warehouse', data);

// 删除仓库设置
export const deleteWareHouse = (id: string) =>
  requestClient.delete<WareHouse.GetListReturn>(`/mes/wm/warehouse/${id}`);

// 获取自动生成编码
export const getWareHouseCode = () =>
  baseRequestClient.get<any>('/system/autocode/get/WAREHOUSE_CODE');
